!function () {
    $('.header-last').text('购物车（' + JSON.parse(localStorage.getItem('nuabAll')) + '）')
    var List = $('.header-left ul li:last-child'),
        NavLi = $('.header-nav li:first-child'),
        BoxLi = $('.header-baoxiao ul li,.right_con_book'),
        ListR = $('.header-right ul li:first-child'),
        headerLast = $('.header-right ul li:last-child'),
        user


    BoxLi.on('mouseenter', function () {
        $(this).find('.qwe').stop().fadeIn()
    })
    BoxLi.on('mouseleave', function () {
        $(this).find('.qwe').stop().fadeOut()
    })

    headerLast.on('mouseenter', function () {
        $(this).find('.header-Gosppsa').stop().slideDown()
        RenderFunBoy()
    })
    headerLast.on('mouseleave', function () {
        $(this).find('.header-Gosppsa').stop().slideUp()
    })


    ListR.on('mouseenter', function () {
        $(this).find('.header-hide').stop().slideDown()
    })
    ListR.on('mouseleave', function () {
        $(this).find('.header-hide').stop().slideUp()
    })
    NavLi.on('mouseenter', function () {
        $(this).find('.header-xiala').stop().slideDown()
    })
    NavLi.on('mouseleave', function () {
        $(this).find('.header-xiala').stop().slideUp()
    })
    List.on('mouseenter', function () {
        $(this).find('.header-show').stop().slideDown()
    })
    List.on('mouseleave', function () {
        $(this).find('.header-show').stop().slideUp()
    })

    //跳转所有宝贝
    $('#allbabyClick').on('click', function () {
        location.href = 'allbaby.html'
    })
    //跳转购物页面
    $('#shopping').on('click', function () {
        if (user) {
            location.href = 'shopping.html'
        } else {
            location.href = 'login.html'
        }
    })
    //跳转首页
    $('#indexClick').on('click', function () { location.href = 'index.html' })
    //跳转注册页面
    $('#registerClick').on('click', function () { location.href = 'register.html' })
    //跳转登陆页面
    $('#loginClick').on('click', function () { location.href = 'login.html' })
    //判断登陆状态
    userOrFun()
    function userOrFun() {
        user = JSON.parse(localStorage.getItem('user')) || false
        if (user.success) {
            $('.beforelogin').hide()
            $('.loginAfter').show()
            $('#userName').html(user.data.name)
        } else {
            $('.beforelogin').show()
            $('.loginAfter').hide()
        }
    }
    //退出登录
    $('#backuser').on('click', function () {
        localStorage.removeItem('user')
        userOrFun()
    })

    //点击购买-跳转详情页
    $('.con-right').on('click', '.con-btn', function () {
        var Bookers = $(this).siblings('input').val()
        sessionStorage.setItem('Bookers', JSON.stringify(Bookers))
        location.href = 'particulars.html'
    })
    $('.picTab').on('click', 'div', function () {
        var Bookers = $(this).find('input[type="hidden"]').val()
        sessionStorage.setItem('Bookers', JSON.stringify(Bookers))
        location.href = 'particulars.html'
    })
    $('.backTop').hide();
    //渲染图片轮播-基础真题
    renderbaisiFun()
    function renderbaisiFun() {
        var arr = [], arr2 = []
        $.ajax({
            url: "http://localhost/80edu/api.php/records/detail",
            method: 'get',
            data: { filter: 'leixing,eq,真题解析' },
            success: function (data) {
                $.each(data.records, function (k, v) {
                    arr.push(
                        '<div><img src="./img/22_20190510152040.png">' +
                        '<p>' + v.name + '</p>' +
                        '<p>￥' + v.price + '</p><input type="hidden" value=' + v.id + '></div>'
                    )
                })
                for (i = 0; i < 4; i++) {
                    arr2.push(
                        '<div class="fr-con-book fl"><div class="fr-con-img"></div>' +
                        '<p class="bookName">' + data.records[i].name + '</p>' +
                        '<p class="bookstyle">规格：' + data.records[i].guige + '</p>' +
                        '<p class="bookstyle">材料：' + data.records[i].caizhi + '</p>' +
                        '<p class="bookpic">￥' + data.records[i].price + '.<span>00</span></p>' +
                        '<div class="con-btn">立即购买</div><input type="hidden" value=' + data.records[i].id + '></div>'
                    )
                }
                $('.playtwo').html(arr.join(''))
                $('.con-righttwo').append(arr2.join(''))
                $('.playtwo').width(($('.playtwo>div').width() * arr.length))
                playFun('.playtwo')
            }
        })
    }
    //渲染图片轮播-公用设备
    rendersharedFun()
    function rendersharedFun() {
        var arr = [], arr2 = [], num = null
        $.ajax({
            url: "http://localhost/80edu/api.php/records/detail",
            method: 'get',
            data: { filter: 'leixing,eq,辅导教材' },
            success: function (data) {
                $.each(data.records, function (k, v) {
                    arr.push(
                        '<div><img src="./img/22_20190510152040.png">' +
                        '<p>' + v.name + '</p>' +
                        '<p>￥' + v.price + '</p><input type="hidden" value=' + v.id + '></div>'
                    )
                })
                for (i = 0; i < 4; i++) {
                    arr2.push(
                        '<div class="conBook fl"><div class="fr-con-img fl"></div><div class="conBook-spe fl">' +
                        '<p class="bookName bookNameTwo">' + data.records[i].name + '</p>' +
                        '<p class="bookstyle">规格：' + data.records[i].guige + '</p>' +
                        '<p class="bookstyle">材料：' + data.records[i].caizhi + '</p>' +
                        '<p class="bookpic">￥' + data.records[i].price + '.<span>00</span></p>' +
                        '<div class="con-btn con-btn-two">立即购买</div><input type="hidden" value=' + data.records[i].id + '></div></div>'
                    )
                }
                var newarr = [arr2[0], arr2[1]], newarr1 = [arr2[2], arr2[3]]
                $('.conBookDivone').html(newarr.join(''))
                $('.conBookDivtwo').html(newarr1.join(''))
                $('.playone').html(arr.join(''))
                $('.playone').width(($('.playone>div').width() * arr.length))
                playFun('.playone')

            }
        })
    }


    //图片轮播
    function playFun(ele) {
        var timer;
        function animateimg() {
            $(ele).animate({ 'margin-left': 0 }, 4000, 'linear', function () {
                $(ele).css('margin-left', '-' + $('.picTab div').width() + 'px').prepend($(ele).find('div:last'))
            })
        }
        lieaverT()
        function lieaverT() {
            timer = setInterval(animateimg, 0)
        }
        $(ele + ' div').on('mouseenter', this, function () {
            $(ele).stop(true);
            clearInterval(timer)
        })
        $(ele + ' div').on('mouseleave', function () {
            lieaverT();
        })
    }
    //回到顶部
    $(window).scroll(function () {
        if (screen.height < $(this).scrollTop()) {
            $('.backTop').slideDown();
        } else {
            $('.backTop').slideUp();
        }
    })
    $('.backTop,.rollbackTop').click(function () {
        console.log(20)
        $('html').animate({ scrollTop: 0 }, 1000)
    })
    //图片淡入淡出
    fadeFun()
    function fadeFun() {
        var timer, index = 0, img = $('.header-Table img'), ul = $('.header-Table ul'), or = true;
        timer = setInterval(function () {
            img.eq(index).fadeIn().siblings('img').fadeOut();
            if (or) {
                index = 1;
                or = false;
            }
            ul.find('li').eq(index).addClass('activeLi').siblings('li').removeClass('activeLi')
            index++;
            if (index == img.length) {
                index = 0;
            }
        }, 3000)
    }
    $('.header-tab li').on('click', function () {
        $(this).addClass('activeLi').siblings('li').removeClass('activeLi')
        $('.header-Table img').eq($(this).index()).fadeIn().siblings('img').fadeOut();
    })
    $('.left_Listers').on('click', '.right_icon', function (e) {
        if ($(this).hasClass('icon-down')) {
            e.stopPropagation()
            $(this).parent().find('div').stop().slideDown()
            $(this).attr('class', 'right_icon iconfont icon-up')
        } else {
            e.stopPropagation()
            $(this).parent().find('div').stop().slideUp()
            $(this).attr('class', 'right_icon iconfont icon-down')
        }
    })

    //渲染首页类别
    renderleibie()
    function renderleibie() {
        $.ajax({
            url: "http://localhost/80edu/api.php/records/classify",
            type: "get",
            success: function (data) {
                var str = '', Nabmers = 1
                $.each(data.records, function (k, v) {
                    if (v.pid == 0) {
                        Nabmers = 1
                        str += "<div class='Daohang' data-text='"+v.title+"'>"
                        str += v.title
                        $.each(data.records, function (i, o) {
                            if (v.id == o.pid) {
                                if (Nabmers == 1) {
                                    str += "<i class='header-jian'></i>"
                                    str += "<div class='header-erji'>"
                                    Nabmers = undefined
                                }
                                str += "<p class='Daohang' data-text='"+o.title+"'>" + o.title + "</p >"
                            }
                        })
                        str += "</div>"
                        str += "</div>"
                    }
                })
                $('.header-xiala').html(str)
            }
        });
    }

    $('.header-xiala').on('click','.Daohang',function(event){
        // $.ajax({
        //     url: "http://localhost/80edu/api.php/records/detail",
        //     method: 'get',
        //     data: { filter: 'type,cs,'+ $(this).attr('data-text')},
        //     success: function (data) {
            console.log($(this).attr('data-text'))
            event.stopPropagation()
                location.href = "allbaby.html?matent=" +JSON.stringify($(this).attr('data-text')) 
            // }
        // })

    })





    function RenderFunBoy() {
        var str = "", nubler = 0
        $.ajax({
            url: 'http://localhost/80edu/api.php/records/shopcar',
            method: 'get',
            success: function (data) {
                $.each(data.records, function (k, v) {
                    nubler += v.price*1
                    if (k == 1 || k == 0 || k == 2 || k == 0) {
                        str += '<li>'
                            + '<img src="./img/ABUIABACGAAgiZi55gUo1sbrigQwwB840Bc!60x60.jpg" alt="">'
                            + '<i style=" font-weight: normal">' + v.goodsname + '</i>'
                            + '<a> 删除 </a>'
                            + '<b>￥' + v.price + '</b>'
                            + '<u>X' + v.num + '</u>'
                            + '</li>'
                    }
                })
                $('.shopping-ueser').html(str)
                $('.All-shang').text('共'+data.records.length+'件商品')
                $('.bottom-jiesuan b').text('￥'+nubler)
            }
        })
    }
}(); 